package com.ozo.easy.controller;

import com.ozo.easy.common.log.annotation.LogAnno;
import com.ozo.easy.common.model.*;
import com.ozo.easy.pojo.dto.SysRoleMenuAuthDTO;
import com.ozo.easy.service.ISysRoleMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;

/**
 * 角色菜单 前端控制器
 *
 * @author ozo
 * @version 1.0
 * @date 2025-02-17 16:53:43
 */
@Tag(name = "角色菜单")
@RequiredArgsConstructor
@RestController
@RequestMapping("/sysRoleMenu")
public class SysRoleMenuController {

    private final ISysRoleMenuService sysRoleMenuService;

    @Operation(summary = "授权页")
    @GetMapping("/authForm/{id}")
    public ModelAndView authForm(@PathVariable Long id) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("roleId", id);
        modelAndView.addObject("data", sysRoleMenuService.detail(id));
        modelAndView.setViewName("sysRoleMenu/authForm");
        return modelAndView;
    }

    @LogAnno(value = "授权菜单", module = "角色菜单")
    @Operation(summary = "授权菜单")
    @PostMapping("/auth")
    public ResultVO<Void> auth(@RequestBody @Valid SysRoleMenuAuthDTO menuAuthDTO) {
        sysRoleMenuService.auth(menuAuthDTO);
        return ResultVO.success();
    }

}